package smecta.client.print.domain.query;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
@NoArgsConstructor
public class PageQuery implements Serializable {
    private static final long serialVersionUID = -5975196250448436710L;
    //当前页码
    private int pageNo = 1;
    //每页条数
    private int pageSize = 20;
    private String fuzzySearch;
    private List<SortQuery> sortList;

    private Integer type;

    private Integer taskOverdueType;

    public int getBegin() {
        if (pageSize <= 0) {
            setPageSize(20);
        }
        return (pageNo - 1) * pageSize;

    }

    public List<SortQuery> getSortList() {
        if (CollectionUtils.isEmpty(this.sortList)) {
            SortQuery sortQuery = new SortQuery("id", "desc");
            List<SortQuery> sortQueryList = new ArrayList<>();
            sortQueryList.add(sortQuery);
            this.sortList = sortQueryList;
        }
        return sortList;
    }


    public String getFuzzySearch() {
        return StringUtils.trimToEmpty(this.fuzzySearch);

    }
}